/**
 * COPYRIGHT (C) 2008 Erica Margetich and Loc Phan 
 * To create a Encode Shuffle Cipher Button for Security Viewer
 * @author Erica Margetich
 * @author Loc Phan
 * @version 1.01 2008-12-07
 */
package edu.sjsu.cs.GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import edu.sjsu.cs.security.ShuffleCipher;

public class EncodeShuffleCipherButton extends JButton
{ 
   /**
    * Construct a encode shuffle cipher button
    * @param aTextfield Enter a key text field
    * @param keyTextField Enter the amount of times it will shuffle
    */
      public EncodeShuffleCipherButton(JTextField aTextfield,JTextField keyTextField)
      {
         super("Encode with Shuffle Cipher");
         TextField = aTextfield;
         KeyTextField = keyTextField;
         ActionListener listener = new ButtonListener();
         this.addActionListener(listener);
      }
      class ButtonListener implements ActionListener
      {
         /**
          * The action performed when the button is pressed
          * @param e the action event that is performed
          * @exception e1 must enter positive integer
          */
         public void actionPerformed(ActionEvent e)
         {
            try
            {
               Key = Integer.parseInt(KeyTextField.getText());
               ShuffleCipher encryption = new ShuffleCipher(Key);
               Label.setText(encryption.encode(TextField.getText()));
            }
            catch(Exception e1)
            {
               Label.setText("Please enter an positive integer smaller than "+Integer.MAX_VALUE+" .");
            }
         }
      }
      /**
       * Create a JLabel for the Encode Shuffle Cipher Button
       * @param aLabel the label for the button
       */
      public void addLabel(JLabel aLabel)
      {
         Label = aLabel;
      }
      //private instance fields
      private JLabel Label;
      private JTextField TextField;
      private JTextField KeyTextField;

      private int Key;
}

